package org.future.wsdl.data;

import java.util.ArrayList;
import java.util.List;

import javax.xml.namespace.QName;

import com.ibm.wsdl.extensions.http.HTTPConstants;
import com.ibm.wsdl.extensions.soap.SOAPConstants;
import com.ibm.wsdl.extensions.soap12.SOAP12Constants;

/**
 * wsdl:binding 元素信息
 * @author dycc
 *
 */
public class WsdlBinding {
    private String name;
    
    private QName type;
    
    private QName extType;
    
    private String transport;
    
    private String style;
    
    private String verb;
    
    private List<WsdlBindingOperation> bindingOperations = new ArrayList<WsdlBindingOperation>();
    
    private WsdlPortType wsdlPortType;
    
    private WsdlPort wsdlPort;
    
    // name
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    // type
    public QName getType() {
        return type;
    }
    public void setType(QName type) {
        this.type = type;
    }
    // extType
    public QName getExtType() {
        return extType;
    }
    public void setExtType(QName extType) {
        this.extType = extType;
    }
    // transport
    public String getTransport() {
        return transport;
    }
    public void setTransport(String transport) {
        this.transport = transport;
    }
    // style
    public String getStyle() {
        return style;
    }
    public void setStyle(String style) {
        this.style = style;
    }
    // verb
    public String getVerb() {
        return verb;
    }
    public void setVerb(String verb) {
        this.verb = verb;
    }
    // bindingOperations
    public List<WsdlBindingOperation> getBindingOperations() {
        return bindingOperations;
    }
    public void setBindingOperations(List<WsdlBindingOperation> bindingOperations) {
        this.bindingOperations = bindingOperations;
    }
    // wsdlPortType
    public WsdlPortType getWsdlPortType() {
        return wsdlPortType;
    }
    public void setWsdlPortType(WsdlPortType wsdlPortType) {
        this.wsdlPortType = wsdlPortType;
    }
    // wsdlPort
    public WsdlPort getWsdlPort() {
        return wsdlPort;
    }
    public void setWsdlPort(WsdlPort wsdlPort) {
        this.wsdlPort = wsdlPort;
    }
    
    // toString
    public String toString(){
        StringBuffer sb = new StringBuffer();
        sb.append("<wsdl:binding");
        sb.append(" name=\"" + name + "\"");
        sb.append(" type=\"" + type.getPrefix() + ":" + type.getLocalPart() + "\"");
        sb.append(">");
        sb.append("\n");
        sb.append("<" + extType.getPrefix() + ":" + extType.getLocalPart());
        if(extType.equals(SOAPConstants.Q_ELEM_SOAP_BINDING)
                || extType.equals(SOAP12Constants.Q_ELEM_SOAP_BINDING)){
            sb.append(" transport=\"" + transport + "\"");
            sb.append(" style=\"" + style + "\"");
        }else if(extType.equals(HTTPConstants.Q_ELEM_HTTP_BINDING)){
            sb.append(" verb=\"" + verb +"\"");
        }
        sb.append(" />");
        sb.append("\n");
        for(int i=0;i<bindingOperations.size();i++){
            sb.append(bindingOperations.get(i));
            sb.append("\n");
        }
        sb.append("</wsdl:binding>");
        return sb.toString();
    }
}
